package com.lipaluma.test.db.internal.assertions;

import static org.junit.Assert.assertEquals;

import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * test a floatant column
 * @author Mario
 */
class DoubleColumn extends Column<Double> {

	private DoubleColumn(Builder builder) {
		super(builder);
	}
	
	@Override
	public void assertValue(ResultSet rs) throws SQLException {
		if(name == null)
			assertEquals(getErrorMessageOnIndexColumn(), expectedValue.doubleValue(), rs.getDouble(index), 0);
		else
			assertEquals(getErrorMessageOnNamedColumn(), expectedValue.doubleValue(), rs.getDouble(name), 0);
	}

	public static DoubleColumn.Builder builder(String request) {
		return new Builder(request);
	}

	public static class Builder extends Column.Builder<Double> {

		public Builder(String request) {
			super(request);
		}

		@Override
		public DoubleColumn.Builder withExpectedValue(String expected) {
			this.expectedValue = Double.parseDouble(expected);
			return this;
		}

		@Override
		public DoubleColumn build() {
			return new DoubleColumn(this);
		}

	}
}
